import java.io.*;

class CpException extends IOException {
    public CpException(String msg) {
        super(msg);
    }

    public void printStackTrace() {
        System.err.println(this);
    }
}

public class Cp {
    private File sp = null;
    private File dp = null;

    public Cp(String src, String dst) throws IOException {
        sp = getSrcFile(src);
        dp = getDstFile(sp, dst);
    }

    static public File getDstFile(File src, String dst) throws IOException {
        File dp = new File(dst);
        if (dp.isDirectory()) {
            dp = new File(dp.getCanonicalPath() +
                                    File.separator + src.getName());
        } else if (dp.exists()) {
            throw new CpException("目标文件已存在!");
        }
        return dp;
    }

    static public File getDstFile(String src, String dst) throws IOException {
        return getDstFile(new File(src), dst);
    }

    static public File getSrcFile(String src) throws IOException {
        File sp = new File(src);
        if (!sp.exists()) {
            throw new CpException("源路径不存在!");
        }
        if (sp.isDirectory()) {
            throw new CpException("暂时不支持复制目录!");
        }
        return sp;
    }

    public static void doCpFile(File sp, File dp) throws IOException {
        byte [] data = new byte[(int)sp.length()];
        FileInputStream is = new FileInputStream(sp);
        is.read(data);
        is.close();
        FileOutputStream os = new FileOutputStream(dp);
        os.write(data);
        os.close();
    }

    public void doCp() throws IOException {
        doCpFile(sp, dp);
    }

    static public void main(String [] args) throws IOException {
        if (args.length < 2) {
            throw new CpException("必须指定源与目标路径!");
        }
        (new Cp(args[0], args[1])).doCp();
    }
}
